﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
using Hezi.BLL;

namespace Hezi
{
    class Program
    {
        private static string name = "abc";
        public static int Pijiu(int count, int gaizi_L, int pingzi_L,int gaizi_Huan,int pingzi_Huan)
        {
            int gaiZi = count; //现有盖子
            int pingZi = count;//现有瓶子
            gaizi_L = 0;//多的盖子
            pingzi_L = 0;//多的空瓶子
            //int gaizi_Huan = 0;//盖子换来的新啤酒
            //int pingzi_Huan = 0;//瓶子换来的新啤酒
            if (gaizi_Huan > 0)
            {
                count += gaizi_Huan;
                gaizi_Huan = 0;
            }
            if (pingzi_Huan > 0)
            {
                count += pingzi_Huan;
                pingzi_Huan = 0;
            }
            int result = count;
            Console.WriteLine("进入:现有{0}瓶,多的盖子{1}个,多的空瓶子{2}个", result,gaizi_L,pingzi_L);
            if (count >= 4)
            {
                gaizi_Huan = count / 4;
                result += gaizi_Huan;
                gaizi_L = count % 4;
            }
            if (count >= 2)
            {
                pingzi_Huan = count / 2;
                result += pingzi_Huan;
                pingzi_L = count % 2;
            }
            Console.WriteLine("结果:现有{0}瓶,其中盖子换来的{1}瓶,瓶子换来的{2},又有新盖子", result,gaizi_Huan,pingzi_Huan);
            if (gaizi_L >= 4 || pingzi_L >= 2)
            {
                int piJIu = result;//满屏的啤酒
                int Gz=result+=
               result+= Pijiu(gaizi_Huan + pingzi_Huan, gaizi_L, pingzi_L,gaizi_Huan,pingzi_Huan);
            }
            
            return result;
        }
        static void Main(string[] args)
        {
            int i= Pijiu(3, 0, 0,0,0);
            Console.WriteLine(i);
            //Service();
            //Set("我擦");
            //Get();
            Console.Read();
        }
        public static void Set(string msg)
        {
            CacheManager cm = new CacheManager();
            for(int i = 0; i < 10; i++)
            {
                cm.ListSet(name, i.ToString());
            }
           

            Console.WriteLine("写入成功:"+cm.db.ListLength(name));
        }
        public static void Get()
        {
            CacheManager cm = new CacheManager();
           //var r=  cm.ListGet<string>(name);
            //cm.db.ListLeftPush(name, "23");
            var x = cm.db.ListLength(name);
            Console.WriteLine("条数:"+x);
            //Console.WriteLine("读取:"+r);
        }
        private static void Service()
        {
            using (ServiceHost host = new ServiceHost(typeof(Test), new Uri("http://localhost:8090/test")))
            {
                var webhttp = host.AddServiceEndpoint(typeof(ITest), new WebHttpBinding(), "", new Uri("http://localhost:8090/test"));
                host.AddServiceEndpoint(typeof(ITest), new WSHttpBinding(), "",new Uri("http://localhost:8090/test/ws"));
                
                webhttp.EndpointBehaviors.Add(new WebHttpBehavior());
                if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)

                {
                    ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                    behavior.HttpGetEnabled = true;
                    behavior.HttpGetUrl = new Uri("http://localhost:8090/test/metadata");
                    host.Description.Behaviors.Add(behavior);
                }
                foreach (var item in host.Description.Endpoints)
                {
                    Console.WriteLine("终结点:" + item.Address.Uri.AbsoluteUri);
                    Console.WriteLine(item.Binding.Name);
                    foreach (var b in item.EndpointBehaviors)
                    {
                        Console.WriteLine("终结点行为:" + b.ToString());
                    }
                }
                foreach (var item in host.Description.Behaviors)
                {
                    Console.WriteLine("行为:" + item.ToString());
                }
                host.Opened += (s, e) => Console.WriteLine("服务已启动");
                host.Open();
                Console.Read();
            }

        }
    }
}
